﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Entity;
using System.Collections.Generic;

namespace EZCRS.HCMS.Web.manage.hotel
{
    public partial class roomactadd : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.BasHotelId == 0)
                Response.Write(CFun.AlertMeg(Resources.Site.MustHotel, "back", ""));

            if (!Page.IsPostBack)
            {
                int id = CFun.RequestNumber("id");

                CFun.SetListControl(ddlroomtype, Bllbase_info.getbaseinfo(baseinfotype.房型种类, CFun.CurrentLanguage()), "");
                CFun.SetListControl(ddlbedtype, Bllbase_info.getbaseinfo(baseinfotype.床型, CFun.CurrentLanguage()), "");
                CFun.SetListControl(cblother, Bllbase_info.getbaseinfo(baseinfotype.房型其他, CFun.CurrentLanguage()), "");
                CFun.AddListItems(rblavaliable, EZCRS.HCMS.DataAcl.Common.BoolStatus(), true);
                btnsave.Text = Resources.Site.ButtonSave;
                if (id > 0)
                {
                    List<HCRS_RoomCode> _code = new Bllh_roomcode().getitem(" id="+id.ToString()+" and pid="+base.BasPropertyId.ToString()+" ");
                    if (_code.Count==1)
                    {
                        CFun.bindpagedata<HCRS_RoomCode>(this, _code[0]);
                        CFun.SetMultiList(cblother, _code[0].other);

                        btnsave.Text = Resources.Site.ButtonModify;
                        btndel.Visible = true;
                        btndel.Attributes.Add("onclick", "return confirm('" + Resources.Site.SystemConfirmDelete + "');");
                    }
                }
            }
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            HCRS_RoomCode _code = new HCRS_RoomCode();
            CFun.getpagedata<HCRS_RoomCode>(_code, this);

            _code.pid = base.BasPropertyId;
            _code.userid = base.BasUserId;
            _code.updatetime = DateTime.Now;
            _code.other = CFun.GetMultiList(cblother);
            _code.languagetype = base.LanguageId;

            if(new Bllh_roomcode().insertorupdateitem(_code))
                Page.ClientScript.RegisterClientScriptBlock(typeof(String), "scuress", CFun.AlertMeg(Resources.Site.SystemModifySuccess, "", "roomact.aspx"));
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }

        protected void btndel_Click(object sender, EventArgs e)
        {
            if(new Bllh_roomcode().deleteitem(Convert.ToInt32(hidid.Value)))
                Response.Write(CFun.AlertMeg(Resources.Site.SystemDeleteSuccess, "", "roomact.aspx"));
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }
    }
}
